package com.yfux.cling_player.service;

import com.yfux.cling_player.service.controller.AvTransportControl;

import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.support.avtransport.AVTransportException;
import org.fourthline.cling.support.avtransport.AbstractAVTransportService;
import org.fourthline.cling.support.model.DeviceCapabilities;
import org.fourthline.cling.support.model.MediaInfo;
import org.fourthline.cling.support.model.PositionInfo;
import org.fourthline.cling.support.model.TransportAction;
import org.fourthline.cling.support.model.TransportInfo;
import org.fourthline.cling.support.model.TransportSettings;

public class AVTransportServiceImpl extends AbstractAVTransportService {
    private AvTransportControl avTransportControl;

    public AVTransportServiceImpl(AvTransportControl avTransportControl) {
        this.avTransportControl = avTransportControl;
    }

    @Override
    public UnsignedIntegerFourBytes[] getCurrentInstanceIds() {
        return new UnsignedIntegerFourBytes[]{new UnsignedIntegerFourBytes(0)};
    }

    @Override
    public TransportAction[] getCurrentTransportActions(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getCurrentTransportActions();
    }

    @Override
    public DeviceCapabilities getDeviceCapabilities(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getDeviceCapabilities();
    }

    @Override
    public MediaInfo getMediaInfo(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getMediaInfo();
    }

    @Override
    public PositionInfo getPositionInfo(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getPositionInfo();
    }

    @Override
    public TransportInfo getTransportInfo(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getTransportInfo();
    }

    @Override
    public TransportSettings getTransportSettings(UnsignedIntegerFourBytes instanceId) {
        return avTransportControl.getTransportSettings();
    }

    @Override
    public void next(UnsignedIntegerFourBytes instanceId) {
        avTransportControl.next();
    }

    @Override
    public void pause(UnsignedIntegerFourBytes instanceId) {
        avTransportControl.pause();
    }

    @Override
    public void play(UnsignedIntegerFourBytes instanceId, String speed) {
        avTransportControl.play(speed);
    }

    @Override
    public void previous(UnsignedIntegerFourBytes instanceId) {
        avTransportControl.previous();
    }

    @Override
    public void seek(UnsignedIntegerFourBytes instanceId, String unit, String target) {
        avTransportControl.seek(unit, target);
    }

    @Override
    public void setAVTransportURI(UnsignedIntegerFourBytes instanceId, String currentURI, String currentURIMetaData) {
        try {
            avTransportControl.setAVTransportURI(currentURI, currentURIMetaData);
        } catch (AVTransportException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void setNextAVTransportURI(UnsignedIntegerFourBytes instanceId, String nextURI, String nextURIMetaData) {
        avTransportControl.setNextAVTransportURI(nextURI, nextURIMetaData);
    }

    @Override
    public void setPlayMode(UnsignedIntegerFourBytes instanceId, String newPlayMode) {
        avTransportControl.setPlayMode(newPlayMode);
    }

    @Override
    public void stop(UnsignedIntegerFourBytes instanceId) {
        avTransportControl.stop();
    }

    @Override
    public void record(UnsignedIntegerFourBytes instanceId) {} // ignore

    @Override
    public void setRecordQualityMode(UnsignedIntegerFourBytes instanceId, String newRecordQualityMode) {} // ignore
}